﻿@model IEnumerable<Rehabilitation.Models.Patient>

@{
    ViewBag.Title = "Patients";
}

<div>
    <div class="float-left" style="min-width: 200px;"><h2>Patients</h2></div>
    <div class="float-left">
        @using (Html.BeginForm("Index", "Patients", FormMethod.Post))
        {
            <text>
                <h3>Search Options</h3> DateOfBirth @Html.TextBox("DateOfBirth") Name:@Html.TextBox("Name") <input type="submit" value="search"/>
            </text>
        }
    </div>
</div>
<div class="clear-fix"></div>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table width="100%">
    <tr>
        <th>
            @Html.ActionLink("ID", "Index", new {orderBy = "id", sortOrder=(ViewBag.OrderBy.Equals("id")&&ViewBag.SortOrder.Equals("a")?"d":"a"), DateOfBirth = ViewBag.DateOfBirth, Name=ViewBag.Name})
        </th>
        <th>
            @Html.ActionLink("Date Of Birth", "Index", new {orderBy = "dateOfBirth", sortOrder=(ViewBag.OrderBy.Equals("dateOfBirth")&&ViewBag.SortOrder.Equals("a")?"d":"a"), DateOfBirth = ViewBag.DateOfBirth, Name=ViewBag.Name})
        </th>
        <th>
            @Html.ActionLink("First Name", "Index", new {orderBy = "firstName", sortOrder=(ViewBag.OrderBy.Equals("firstName")&&ViewBag.SortOrder.Equals("a")?"d":"a"), DateOfBirth = ViewBag.DateOfBirth, Name=ViewBag.Name})
        </th>
        <th>
            @Html.ActionLink("Last Name", "Index", new {orderBy = "lastName", sortOrder=(ViewBag.OrderBy.Equals("lastName")&&ViewBag.SortOrder.Equals("a")?"d":"a"), DateOfBirth = ViewBag.DateOfBirth, Name=ViewBag.Name})
        </th>
        <th>
            @Html.ActionLink("Sex", "Index", new {orderBy = "sex", sortOrder=(ViewBag.OrderBy.Equals("sex")&&ViewBag.SortOrder.Equals("a")?"d":"a"), DateOfBirth = ViewBag.DateOfBirth, Name=ViewBag.Name})
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.PatientID)
        </td>
        <td>
            @item.DateOfBirth.Value.Date.ToString("MMM dd, yyyy")
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LastName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Sex)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.PatientID }) |
            @Html.ActionLink("Details", "Details", new { id=item.PatientID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.PatientID })
        </td>
    </tr>
}
    

</table>
@if(ViewBag.NumberOfPages>1)
{
    for(int i = 1; i<= ViewBag.NumberOfPages; i++)
    {
        @Html.ActionLink(i+"", "Index", new {orderBy = ViewBag.OrderBy, sortOrder = ViewBag.SortOrder, page=i, DateOfBirth = ViewBag.DateOfBirth, Name=ViewBag.Name}) 
    }
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.dateFormat-1.0.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
    <script>
        $(document).ready(function () {
            $("#DateOfBirth").datepicker();
        });
        
    </script>
}